package com.yxt.qmgf.snake.view;

import com.yxt.qmgf.common.ClientSession;
import com.yxt.qmgf.snake.ctrl.snakeInfoController;
import com.yxt.qmgf.userinfo.view.UserInfoTab;
import com.yxt.qmgf.userinfo.vo.UserInfoVO;
import javafx.fxml.FXMLLoader;
import javafx.fxml.JavaFXBuilderFactory;
import javafx.scene.control.Tab;
import javafx.scene.layout.Pane;
import java.io.IOException;
import java.net.URL;

public class SnakeTab extends Tab {

    private static volatile SnakeTab instance;

    public UserInfoVO vo = null;
    private SnakeTab() {this("贪吃蛇");}
    private SnakeTab(String str) {
        super(str);
        initView();
    }

    public static SnakeTab getInstance() {
        if (null == instance) {
            synchronized (UserInfoTab.class) {
                if (null == instance) {
                    instance = new SnakeTab();
                }
            }
        }
        return instance;
    }

    private void initView() {
        UserInfoVO vo =(UserInfoVO) ClientSession.getAttribute("user_info");
        URL url = getClass().getResource("/fxml/snake/snakePage.fxml");
        FXMLLoader fxmlLoader = new FXMLLoader();
        fxmlLoader.setLocation(url);
        fxmlLoader.setBuilderFactory(new JavaFXBuilderFactory());
        try {
            Pane pane = fxmlLoader.load();
            pane.getStylesheets().add(getClass().getResource("/css/yxt.css").toExternalForm());
            setContent(pane);
        } catch (IOException e) {
            e.printStackTrace();
        }
        setClosable(true);
        snakeInfoController controller =fxmlLoader.getController();
        controller.setOff(vo);
    }
}
